 

#include "frameworks/bridge/declarative_frontend/jsview/js_mycircle.h"

#include "base/log/ace_scoring_log.h"
#include "core/common/container.h"
#include "core/components_ng/pattern/mycircle/mycircle_model.h"
#include "core/components_ng/pattern/mycircle/mycircle_model_ng.h"

namespace OHOS::Ace {

std::unique_ptr<MyCircleModel> MyCircleModel::instance_ = nullptr;

MyCircleModel* MyCircleModel::GetInstance()
{
    if (!instance_) {
#ifdef NG_BUILD
        instance_.reset(new NG::MyCircleModelNG());
#else
        if (Container::IsCurrentUseNewPipeline()) {
            instance_.reset(new NG::MyCircleModelNG());
        } else {
            instance_.reset(new NG::MyCircleModelNG());
            // instance_.reset(new Framework::MyCircleModelImpl());
        }
#endif
    }
    return instance_.get();
}

} // namespace OHOS::Ace

namespace OHOS::Ace::Framework {
void JSMyCircle::SetRadius(const JSCallbackInfo& info)
{
    if (info.Length() < 1) {
        LOGE("The arg is wrong, it is supposed to have at least 1 arguments");
        return;
    }
    CalcDimension value;
    if (!ParseJsDimensionVp(info[0], value)) {
        return;
    }
    MyCircleModel::GetInstance()->SetRadius(value);
}

void JSMyCircle::SetEdgeColor(const JSCallbackInfo& info)
{
    if (info.Length() < 1) {
        LOGE("The arg is wrong, it is supposed to have atleast 1 arguments");
        return;
    }

    Color color;
    if (!ParseJsColor(info[0], color)) {
        return;
    }
    MyCircleModel::GetInstance()->SetEdgeColor(color);
}

void JSMyCircle::SetEdgeWidth(const JSCallbackInfo& info)
{
    if (info.Length() < 1) {
        LOGE("The arg is wrong, it is supposed to have at least 1 arguments");
        return;
    }
    CalcDimension value;
    if (!ParseJsDimensionVp(info[0], value)) {
        return;
    }
    MyCircleModel::GetInstance()->SetEdgeWidth(value);
}

void JSMyCircle::Create()
{
    MyCircleModel::GetInstance()->Create();
}

void JSMyCircle::JSBind(BindingTarget globalObj)
{
    JSClass<JSMyCircle>::Declare("MyCircle");
    MethodOptions opt = MethodOptions::NONE;
    JSClass<JSMyCircle>::StaticMethod("create", &JSMyCircle::Create, opt);
    JSClass<JSMyCircle>::StaticMethod("circleRadius", &JSMyCircle::SetRadius);
    JSClass<JSMyCircle>::StaticMethod("circleEdgeColor", &JSMyCircle::SetEdgeColor);
    JSClass<JSMyCircle>::StaticMethod("circleEdgeWidth", &JSMyCircle::SetEdgeWidth);
    JSClass<JSMyCircle>::StaticMethod("onCircleClick", &JSInteractableView::JsOnClick);
    JSClass<JSMyCircle>::Inherit<JSViewAbstract>();
    JSClass<JSMyCircle>::Bind<>(globalObj);
}
} // namespace OHOS::Ace::Framework
